# -*- coding: utf-8 -*-
import scrapy
from meizitu.items import MeizituItem
import time
class MeiziSpider(scrapy.Spider):
    name = 'meitu'
    allowed_domains = ['www.meizitu.com']
    baseURL = 'http://www.meizitu.com/a/'
    offset = 4633
    end    = '.html'
    start_urls = [baseURL+str(offset)+end]

    def parse(self, response):
        srcs = response.css(".postContent img::attr(src)").extract()
        for src in srcs :
            item = MeizituItem()
            item['picLink'] = src
            print(src)
            yield item
        self.offset +=1
        print('zzz'+str(self.offset))
        if self.offset > 5400:  #stop at 5400,for 404    5586
            return
        time.sleep(1)
        url = self.baseURL + str(self.offset)+self.end
        print ("url:"+url)
        yield scrapy.Request(url, callback=self.parse)

